package iammry.com.ui;


import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import iammry.com.R;


	public class CustomProgressDialog extends Dialog {
		private Context context = null;
		private static CustomProgressDialog customProgressDialog = null;


		public CustomProgressDialog(Context context) {
			super(context);
			this.context = context;
			
		}

		public CustomProgressDialog(Context context, int theme) {
			super(context, theme);
			this.context = context;
			
		}

		public static CustomProgressDialog createDialog(Context context) {
			customProgressDialog = new CustomProgressDialog(context,
					R.style.CustomProgressDialog);

			customProgressDialog.setContentView(R.layout.customprogressdialog);

			customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

			return customProgressDialog;
		}

		public void onWindowFocusChanged(boolean hasFocus) {

			if (customProgressDialog == null) {
				return;
			}

			ImageView imageView = (ImageView) customProgressDialog
					.findViewById(R.id.loadingImageView);

			AnimationDrawable animationDrawable = (AnimationDrawable) imageView
					.getBackground();
			animationDrawable.start();
		}

		public boolean IsdissmissMyDialog() {
			boolean isSuccess = false;

			if (customProgressDialog == null) {
				isSuccess = true;
			}
			if (customProgressDialog.getWindow() == null) {
				isSuccess = true;
			}
			return isSuccess;
		}

		@Override
		public void dismiss() {
			
				super.dismiss();
			
		}

		@Override
		public void show() {
			
		
				super.show();
			

		}

		/**
		 * 
		 * [Summary] setTitile ����
		 * 
		 * @param strTitle
		 * @return
		 * 
		 */
		public CustomProgressDialog setTitile(String strTitle) {
			return customProgressDialog;
		}

		/**
		 * 
		 * [Summary] setMessage ��ʾ����
		 * 
		 * @param strMessage
		 * @return
		 * 
		 */
		public CustomProgressDialog setMessage(String strMessage) {
			TextView tvMsg = (TextView) customProgressDialog
					.findViewById(R.id.id_tv_loadingmsg);

			if (tvMsg != null) {
				tvMsg.setText(strMessage);
			}

			return customProgressDialog;
		}
}
